package com.jz.warehouseareaclass.conroller;

//import com.jz.subclass.test.SubStatusEnum;

import com.jz.util.ResultBuildVo;
import com.jz.util.ResultVo;
import com.jz.warehouseareaclass.model.WarehouseareaAddVo;
import com.jz.warehouseareaclass.model.WarehouseareaSelectVo;
import com.jz.warehouseareaclass.model.WarehouseareaUpdateStatusVo;
import com.jz.warehouseareaclass.model.WarehouseareaUpdateVo;
import com.jz.warehouseareaclass.service.WarehouseareaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * Created by WISE on 2021/12/26.
 */
@RestController
@CrossOrigin//开启跨域
@RequestMapping("storageSection")
public class WarehouseareaController {


    //1.首页分页
    @Autowired
    private WarehouseareaService warehouseareaService;

    @PostMapping("queryPage")
    public ResultVo firstPage(@RequestBody WarehouseareaSelectVo warehouseareaSelectVo) {
        ResultVo resultVo = warehouseareaService.firstPage(warehouseareaSelectVo);

        return resultVo;
    }

//    //2.新增
    @PostMapping("add")
    @Transactional
    public ResultVo add(@RequestBody @Valid WarehouseareaAddVo partAddVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = warehouseareaService.addpartClass(partAddVO);
        return resultVo;
    }

   @PostMapping("update")
    public ResultVo update(@RequestBody @Valid WarehouseareaUpdateVo partUpdateVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
       return warehouseareaService.updateSubClass(partUpdateVo);
   }
//
    @PostMapping("updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid WarehouseareaUpdateStatusVo partUpdateStatusVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return warehouseareaService.updateStatus(partUpdateStatusVo);
    }
    @GetMapping("queryStorageSectionById")
    public ResultVo queryStorageSectionById(@RequestBody @Valid Integer id, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return warehouseareaService.queryStorageSectionById(id);
    }

}



